package com.example.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.sys.entity.Scheduling;
import com.example.sys.mapper.SchedulingMapper;
import com.example.sys.service.ISchedulingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wuage
 * @since 2023-12-22
 */
@Service
public class SchedulingServiceImpl extends ServiceImpl<SchedulingMapper, Scheduling> implements ISchedulingService {


    @Override
    public Map<String, List<Scheduling>> listAll() {
        Map<String, List<Scheduling>> listMap = new HashMap<>();
        QueryWrapper<Scheduling> QueryWrapper = new QueryWrapper<>();
        List<Scheduling> list = this.list(QueryWrapper);
        for (Scheduling l : list) {
            //判断是否存在该key
            if (listMap.containsKey(String.valueOf(l.getDate()))) {
                //存在就获取该key的value然后add
                listMap.get(String.valueOf(l.getDate())).add(l);
            } else {
                List<Scheduling> lt = new ArrayList<>();
                lt.add(l);
                //不存在就put
//                listMap.put(l.getDate(), lt);
                listMap.put(String.valueOf(l.getDate()),lt);
            }
        }
        return listMap;
    }

    @Override
    public Map<String, List<Scheduling>> getSchedulingrById(Integer id) {
        Map<String, List<Scheduling>> listMap = new HashMap<>();
        QueryWrapper<Scheduling> QueryWrapper = new QueryWrapper<>();
        QueryWrapper.eq("user_id",id);
        List<Scheduling> list = this.list(QueryWrapper);
        for (Scheduling l : list) {
            //判断是否存在该key
            if (listMap.containsKey(String.valueOf(l.getDate()))) {
                //存在就获取该key的value然后add
                listMap.get(String.valueOf(l.getDate())).add(l);
            } else {
                List<Scheduling> lt = new ArrayList<>();
                lt.add(l);
                //不存在就put
//                listMap.put(l.getDate(), lt);
                listMap.put(String.valueOf(l.getDate()),lt);
            }
        }
        return listMap;
    }
}
